package com.dhsc.service.impl.xtqxgl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhsc.domain.ywzx.xtqxgl.XtyhrzVo;
import com.dhsc.domain.yypt.LayuiTableVo;
import com.dhsc.domain.yypt.ResponseObject;
import com.dhsc.exception.MyException;
import com.dhsc.local.dao.xtqxgl.IXtyhrzDao;
import com.dhsc.service.xtqxgl.IXtyhrzService;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName: XtyhrzServiceImpl
 * @Description: 系统用户认证
 * @date: 2023/11/14 13:59
 * @author: gx
 */
@Service
@Slf4j
public class XtyhrzServiceImpl implements IXtyhrzService {

    @Autowired
    private IXtyhrzDao xtyhrzDao;

    @Override
    public LayuiTableVo queryXtyhrz(XtyhrzVo xtyhrzVo) {
        LayuiTableVo obj = new LayuiTableVo();
        try {
            PageMethod.startPage(xtyhrzVo.getPage(), xtyhrzVo.getLimit());
            List<XtyhrzVo> list = xtyhrzDao.queryXtyhrz(xtyhrzVo);
            PageInfo<XtyhrzVo> pageInfo = new PageInfo<>(list);
            obj.setData(list);
            obj.setMsg("");
            obj.setCount(pageInfo.getTotal());
            obj.setCode(0);
        }catch (Exception e){
            log.error("查询系统用户认证信息出错",e);
            throw new MyException("查询系统用户认证信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryYhxx(XtyhrzVo xtyhrzVo) {
        ResponseObject obj = new ResponseObject();
        try {
            List<XtyhrzVo> list = xtyhrzDao.queryYhxx(xtyhrzVo);
            obj.setData(list);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("查询OA用户信息出错", e);
            throw new MyException("查询OA用户信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject queryYhxxByDhzb(XtyhrzVo xtyhrzVo) {
        ResponseObject obj = new ResponseObject();
        try {
            List<XtyhrzVo> list = xtyhrzDao.queryYhxxByDhzb(xtyhrzVo);
            obj.setData(list);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("查询东海总部OA用户信息出错", e);
            throw new MyException("查询东海总部OA用户信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject saveXtyhrz(XtyhrzVo xtyhrzVo) {
        ResponseObject obj = new ResponseObject();
        try {
            xtyhrzDao.insertXtyhrz(xtyhrzVo);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("分配系统用户认证信息出错", e);
            throw new MyException("分配系统用户认证信息出错",e);
        }
        return obj;
    }

    @Override
    public ResponseObject deleteXtyhrz(XtyhrzVo xtyhrzVo) {
        ResponseObject obj = new ResponseObject();
        try {
            xtyhrzDao.deleteXtyhrz(xtyhrzVo);
            obj.setStatus(200);
        } catch (Exception e) {
            log.error("取消系统用户认证信息出错", e);
            throw new MyException("取消系统用户认证信息出错",e);
        }
        return obj;
    }
}
